小编Abh*_*Rao的帖子

while的目的(1); C中的陈述

有什么用途while(1);?我知道while(1)(没有分号)无限循环,类似于自旋锁情况.但是我没看到哪里while(1);可以使用?

示例代码

if(!condition)
{ 
  while(1);
}
Run Code Online (Sandbox Code Playgroud)

注意:这不是do- while()或简单的情况while(1).

c while-loop

54
推荐指数
6
解决办法
4万
查看次数

Perl中push和unshift有什么区别?

有人可以解释为什么push的行为方式如下所示?

基本上,我想打印由填充的数组值push,以及unshift.

当我尝试打印push使用数组索引填充的数组内容时,它总是在数组顶部打印元素,而填充的数组则unshift打印基于数组索引的数组内容.我不明白为什么.

与不合时宜的

#!/usr/bin/perl
@names = ("Abhijit","Royal Enfield","Google");
@numbers=();
$number=1;
$i=0;
foreach $name (@names) {
    #print $_ . "\n";
    $number=$number+1;
    #push(@numbers,($number));
    unshift(@numbers,($number));
    print("Array size is :" . @numbers . "\n");
    $i=$i+1;
    print("Individual Elements are:" . @numbers[i] . "\n");
    pop(@numbers);
}

rhv:/var/cl_ip_down>./run.sh
Array size is :1
Individual Elements are:2
Array size is :2
Individual Elements are:3
Array size is :3
Individual Elements are:4
Run Code Online (Sandbox Code Playgroud)

没有移位

#!/usr/bin/perl
@names = ("Abhijit","Royal Enfield","Google");
@numbers=();
$number=1;
$i=0; …
Run Code Online (Sandbox Code Playgroud)

perl

6
推荐指数
3
解决办法
7428
查看次数

标签 统计

c ×1

perl ×1

while-loop ×1