标签: while-loop

将 0 到 100 之间的数字相加

int x = -1;
int y = 0;
while(x<100)
{
    x++;
    y+=x;
    System.out.println(y);
}
Run Code Online (Sandbox Code Playgroud)

使用 while 循环求 0 到 100 之间所有整数的总和

我已经泄露了这段代码,它给了我一个数字 5050,我不确定它是否正确。

java loops while-loop

-3
推荐指数
1
解决办法
2812
查看次数

while()循环意外迭代

program
int main()
{
    int a=0xabcd;
    char *p=&a;
    while(p)
    {
        if(*p=='c')
        {
            printf("i got %c\n",*p);
            return; 
        }
        p++;
    }

}
Run Code Online (Sandbox Code Playgroud)

1)为什么我总是得到一个像"我得到c"的答案.
2)无论我执行多少次这个程序,为什么我得到%c为c.
3)用任何字符替换c字符,无论如何,为什么我们得到这样一个字符,如果条件,我们放入什么?

if(*p=='z') or if(*p=='t') or .... 
Run Code Online (Sandbox Code Playgroud)

4)任何人都可以解释是什么原因?

c pointers while-loop

-3
推荐指数
1
解决办法
155
查看次数

将for循环转换为while循环以解析行

我编写了以下for循环来将一些行解析为dict中的键和值.如何将其转换为while循环?

for i in range(len(lines)):
    string = lines[i].rstrip("\n")
    for j in range (len(string)):
        if string[j] == ':':
            user[string[:j]] = string[j+1:]
Run Code Online (Sandbox Code Playgroud)

python for-loop while-loop

-3
推荐指数
1
解决办法
74
查看次数

虽然声明没有身体?

我在一个程序中有许多语句,如下所示:

while( x + ++flips < 8 && board[x + flips][y] == opponent );
Run Code Online (Sandbox Code Playgroud)

(标准"Oracle")编译器返回错误:"虽然语句没有正文." 这是语言规范所要求的,还是编译器特定的?有什么样的黑客我可以使用它来实现这个或者我不能重写它吗?

java syntax loops while-loop

-3
推荐指数
1
解决办法
1129
查看次数

python,请告诉我什么是错的

蟒蛇,请帮忙.我希望这段代码可以询问某人是否可以获得成绩.如果他们说是,那就打印好了!如果他们说不,那就说哦!如果他们不说是或否,我希望它打印"请输入是或否"并继续问他们,直到他们最后说是或否.这是我到目前为止,当我运行它并且不输入是或否,它垃圾邮件"请输入是或否"数百万时间

theanswer= raw_input("Are you ok with that grade?")
while theanswer:
    if theanswer == ("yes"):
        print ("good!")
        break
    elif theanswer == ("no"):
        print ("oh well")
        break
    else: 
        print "enter yes or no"
Run Code Online (Sandbox Code Playgroud)

我需要做什么才能使它工作,我一直在努力

python if-statement raw-input while-loop

-3
推荐指数
1
解决办法
103
查看次数

陷入Infinite While Loop,该怎么做

这不接受任何答案:

cout << "Restart yes or no: ";
cin >> retry;
while (retry != "yes" or retry != "no"){
    cout << "Restart yes or no: ";
    cin >> retry;
    system("cls");
}
Run Code Online (Sandbox Code Playgroud)

如果任何人可以提供替代/修复,将不胜感激.

c++ loops infinite while-loop

-3
推荐指数
1
解决办法
307
查看次数

c#否则没有按预期工作

    {
        Random r = new Random();
        int current = 0;
        int noa = 0;
        while (current != 6) {
            current =r.Next(1,7);
                noa += 1;
                Console.WriteLine(current + " has been rolled.");
        }

        if (noa >= 10)
        {
            Console.WriteLine("You were unlucky and it took you "+ noa + " times to roll a 6!");
        }
        if (noa <= 5)
        {
            Console.WriteLine("You were quite lucky and it took you " + noa + " times to roll a 6!");
        }
        else
        {
            Console.WriteLine("It …
Run Code Online (Sandbox Code Playgroud)

c# if-statement while-loop

-3
推荐指数
1
解决办法
1863
查看次数

while和do-while循环的区别

有人可以解释有两种不同类型的while循环的目的吗?我是编程新手.如果可能的话,还提供带有正确while循环的示例情况.

我理解如何使用while循环.这就是我所做的:

bool myBool = true;
int i = 0;

while (myBool) {
  if (i > 10) {
      myBool = false;
  }
  i = i + 1;
}
Run Code Online (Sandbox Code Playgroud)

c++ loops while-loop do-while

-3
推荐指数
1
解决办法
4269
查看次数

c 的 if、switch 和 while 条件中的打印语句

有人可以解释为什么代码打印 "HelloWorld" 而不是 "HelloWorldThere" 吗?另外,为什么它会打印任何内容,因为 if 或 switch 语句中没有条件?这是代码:

#include <stdio.h>

int main()
{
    int a, b;

    if(printf("Hello"))
        switch(printf("World"))
            while(printf("There"))
            {
                return 0;
            }
}
Run Code Online (Sandbox Code Playgroud)

c printf if-statement while-loop switch-statement

-3
推荐指数
2
解决办法
195
查看次数

是什么导致这个 while 函数终止?

我正在尝试编写将指针变量分配给数组索引的代码。这是代码:

#include <stdio.h>

int main()
{
    int x;
    int iChoice;
    int *iArray[4];
    int iNumber;
    *iArray = iNumber;

    for (x = 0; x < 5; x++) {
        iArray[x] = '\0';
    }

    do {
        system("clear");
        printf("\n\t\tENTER NUMBERS INTO AN ARRAY\n");
        printf("\nArray element #1: %d", iArray[0]);
        printf("\nArray element #2: %d", iArray[1]);
        printf("\nArray element #3: %d", iArray[2]);
        printf("\nArray element #4: %d", iArray[3]);
        printf("\nArray element #5: %d", iArray[4]);
        printf("\n\nEnter an array number to access: ");
        scanf("%d", &iChoice);
    } while (iChoice = NULL);

    do {
        printf("\n\t\tEnter …
Run Code Online (Sandbox Code Playgroud)

c while-loop do-while

-3
推荐指数
1
解决办法
70
查看次数