标签: while-loop

循环时while(1)vs while(3)或任何数字

使用while循环时写入while(1)与任何其他数字相比意味着什么?

在我的计划while(1)中给我同样的答案while(3)

int num1;
int loopcount;

while(1) {
    printf("enter your positive number:");
    scanf("%d",&num1);
    if(num1>0) {
        break;
    }
}
Run Code Online (Sandbox Code Playgroud)

loops while-loop do-while

1
推荐指数
1
解决办法
948
查看次数

在java中打破while循环

我真的不明白为什么它没有突破循环.这是我的计划:

public static void main(String[] args) {

    Scanner input = new Scanner (System.in);

    double tution, rate, r, t, realpay, multiply, start;
    start = 0;

    while(start != -1)
    {
        System.out.print("Press 1 to start, -1 to end: ");
        start = input.nextDouble();

        System.out.print("Please enter the current tution fee for the year: ");
        tution = input.nextDouble();

        System.out.print("Enter in the amount of interest: ");
        rate = input.nextDouble();

        r = 1 + rate;

        System.out.print("Please enter the number of years: ");
        t = input.nextDouble();
        multiply = Math.pow(r,t); …
Run Code Online (Sandbox Code Playgroud)

java loops while-loop

1
推荐指数
1
解决办法
2万
查看次数

Java while循环在一次迭代后停止

我正在尝试创建一个岩石,纸张,剪刀,蜥蜴,spock程序,重复自己,直到用户选择退出.但是,我无法弄清楚如何使程序循环.它在一场比赛后继续存在.我认为这可能与我的while语句的设置方式有关,但我不完全确定如何解决它.谢谢.

import java.util.Scanner;
import java.util.Random;

public class project2_rpsls {

public static void main(String[] args) 
{
    int round=0;
    String uMove = null, cMove = null/*, loop*/;
    Scanner scan=new Scanner(System.in);
    /*System.out.println("Would you like to play?");
    loop=scan.next();
    loop=loop.toUpperCase();
    while (loop.equals("Y"))*/

        while (round>=0) 
        {
            round++;
        }
        //get the moves
        {
        uMove = getuMove();
        cMove = getcMove();
        }
        //Determining the winner
        {
            String winner;
                if (cMove.equals(uMove))
                        {
                        winner="It was a tie!";
                        }
                else if (uMove.equals("ROCK") && cMove.equals("LIZARD") ||
                        uMove.equals ("ROCK") && cMove.equals("SCISSORS"))
                        {
                        winner="You Win!"; …
Run Code Online (Sandbox Code Playgroud)

java loops while-loop

1
推荐指数
1
解决办法
1669
查看次数

c - strtok和while循环终止问题

基本上我试图在每次遇到空格时将用户输入连接到一个char数组(源)数组.换句话说,如果sourceHold包含"祝你生日快乐",则源的数组内容将为"happy"(0),"birthday"(1),"to"(2),"you"(at) 3).sourcesTag保存char数组数组的当前索引.退出循环时我总是遇到错误(代码总是会在它完全退出循环之前中断.最后"LOOP EXIT"打印行永远不会打印.放置那里测试什么是错误的.任何想法为什么我的循环不会终止?im猜测这是因为当整个输入字符串被标记化时,while语句没有正确终止,但是什么是一个好的陈述?

while(sourceHold != NULL)
    {
        if(sourceHold[0] == '\n')
            break;

        printf("%s \n", sourceHold);

        strcpy(sources[sourcesTag], strtok(sourceHold, " "));
        sourcesTag++;

        strcpy( sourceHold, strtok(NULL, "\n"));
    } 
    printf("LOOP EXIT");
Run Code Online (Sandbox Code Playgroud)

c strtok while-loop

1
推荐指数
1
解决办法
6042
查看次数

Java连续循环(循环无需等待)

我希望有一个循环连续运行而无需等待循环中的东西.例如,在下面的示例中,我想迭代一个列表并调用一个名为doS​​omething()的方法,并且一旦调用doSomething()方法,我希望循环继续到第二个项目,第三个项目,等......

 while(it.hasNext())
 {
    MyObject obj = (MyObject)it.next();
    doSomething(obj);
 }
Run Code Online (Sandbox Code Playgroud)

它可以用轮询器完成,但我不想用轮询器来完成.

感谢您的帮助.

java iterator while-loop

1
推荐指数
1
解决办法
969
查看次数

Python"while"循环并打破它们

如果我有两个while:循环,一个在另一个内部,如下:

while #test :
    while #test :
        #other code
        if #test :
           break
    #other code
Run Code Online (Sandbox Code Playgroud)

将break同时停止while:循环或只有一个地方的if #test :是吗?

谢谢您的帮助!

python loops while-loop

1
推荐指数
1
解决办法
147
查看次数

PHP循环时的HTML表单

如何将html表单放入PHP while循环中?

它认为是这样的,但它不起作用:

<?php

$i=1;
while ($i<=5){

<form name="X" action="thispage.php" method="POST">
     <input type="text">
     <input type="submit">
</form>;

$i=$i+1;

              }

?>
Run Code Online (Sandbox Code Playgroud)

html php forms loops while-loop

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

我可以使用while在PHP中什么也不做,如果可能的话,这是一个好的做法吗?

我想在PHP中做这样的事情

function doSomething() { /* ... */ }

while(my_array[] = doSomething()) { }
Run Code Online (Sandbox Code Playgroud)

而不是使用额外的变量: while(myValue = doSomething()) { myArray[] = myValue; }

使用while block什么都不做好练习?如果不是 - 为什么?

php loops while-loop

1
推荐指数
2
解决办法
238
查看次数

在python猜猜游戏

我刚刚开始学习http://learnpythonthehardway.org之后的课程.在了解了循环和if语句之后,我想尝试制作一个简单的猜谜游戏.

问题是:

如果你做出了不正确的猜测,它就会卡住,只是不断重复"太高"或"太低",直到你达到crtl C.

我已阅读有关while循环并阅读其他人的代码,但我只是不想只是复制代码.

print ''' This is the guessing game! 
A random number will be selected from 1 to 10.
It is your objective to guess the number!'''

import random

random_number = random.randrange(1, 10)
guess = input("What could it be? > ")
correct = False

while not correct:
    if guess == random_number:
        print "CONGRATS YOU GOT IT"
        correct = True
    elif guess > random_number:
        print "TOO HIGH"
    elif guess < random_number:
        print "TOO LOW"
    else:
        print …
Run Code Online (Sandbox Code Playgroud)

python while-loop

1
推荐指数
1
解决办法
9165
查看次数

Python break函数不会在true时结束

为什么休息时间不会结束,而是回到起点?

while True:
    print('This is a quiz')
    print('What is your name?')
    Name = input()
    print('Hello ' + Name + ', The quiz will now begin')
    import time
    time.sleep(2)
    question1 = "Question one: "
    answer1 = "True" and "true"
    print(question1)
    qanswer = input()

    if qanswer != answer1:
        print('Sorry, the answer is: ' + answer1)
        break

    if answer1 == qanswer:
            print("Correct! Here's the next question")
Run Code Online (Sandbox Code Playgroud)

我对python很新,所以我认为它只是对这些术语的简单滥用.

python break while-loop

1
推荐指数
1
解决办法
7054
查看次数

标签 统计

while-loop ×10

loops ×6

java ×3

python ×3

php ×2

break ×1

c ×1

do-while ×1

forms ×1

html ×1

iterator ×1

strtok ×1