while-loop

Multiple ways to move through an Iterator

Hi, When I use an Iterator of Object I use a while loop (as written in every book learning Java, as Thinking in Java of Bruce Eckel): Iterator it=... while(it.hasNext()){ //... } but sometime i saw than instead somebody use the for loop: Iterator it=... for (Iterator it=...; it.hasNext();;){ //... } I dont' understand this...

Why is "while" so popular in C#?

The question field is a bit too short to pose my real question. If anyone can recapitulate it better, please feel free. My real question is this: I'm reading a lot of other people's code in C# these days, and I have noticed that one particular form of iteration is widely spread, (see in code). My first question is: Are all these iter...

Display text once within while loop on the first loop

<?php $i = 0; while(conditionals...) { if($i == 0) print "<p>Show this once</p>"; print "<p>display everytime</p>"; $i++; } ?> Would this only show "Show this once" the first time and only that time, and show the "display everytime" as long as the while loop goes thru? ...

immediate exit while loop c++

How do I exit a while loop immediately without going to the end of the block? e.g. while(choice!=99) { cin>>choice; if (choice==99) //exit here and don't get additional input cin>>gNum; } any ideas? ...

Perl loop stuck reading file?

Closing this question. Will drink red bull. Sleep. Code and come back with brand spanking new question with unit test cases. UPDATE: The new file is here Also the config file is here I refactored the code again: sub getColumns { open my $input, '<', $ETLSplitter::configFile or die "Error opening '$ETLSpliter::configFile':...

Any reason to replace while(condition) with for(;condition;) in C++?

Looks like while( condition ) { //do stuff } is completely equivalent to for( ; condition; ) { //do stuff } Is there any reason to use the latter instead of the former? ...

Java while loop not looping

I have the following button in my swing interface private void solveButtonMouseClicked(java.awt.event.MouseEvent evt) { step1(); } which calls step1(); private void step1(){ //step 1 solving the white cross around the yellow middle while( (!(F2.getBackground().equals(w...

Can't read variable that was stored from within a while loop, when out of the while loop.

I can't for the life of me see why I can not read the postPrioity outside the while loop. I tried "export postPrioity="500"" still didn't work. Any ideas? -- or in plan text -- #!/bin/bash cat "/files.txt" | while read namesInFile; do postPrioity="500" #This one shows the "$postPrioity" varible, as '500' echo "weeeeeeeeee --...

C++ STD Cin error in while loop

Why when I entered the loop below and I type something the first instruction cmdstd:getline(std::cin,cmdInput); does not read the input entered. For instance if I entered "b 8" it should display "cmd is b 8", but it skips to the next read std::getline(std::cin, input); and displays "it is b" instead while (editingMode == TRUE) { std...

For loop in while loop

Hi, can I put a for loop in while loop? For example: while($end = 1) { for ($i = 0; $i < count($match); $i++) { $mathcas = $match[$i][1]; } } Thanks. :) ...

Learning C (via K&R) using xcode

Hi, I'm learning C with The C Programming Language (K&R). Since I don't particularly want to bob back and forth between a text editor and running gcc, I've decided to use xcode as an IDE. So far, I've been able to follow the book's examples without a problem up until section 1.5.2. When given the valid (?) program... #include <stdio.h...

Beginner Question - Exiting while loop, input type double as condition, C++

Hi, I've only just recent began learning C++ and am having a little issue with while loops when the condition for the while loop is an input, of type double, from the user. I understand that if the user doesn't enter a value compatible with the double type then the loop is automatically broken. The issue is my console application exits u...

php function with a while-loop

Hi I have a function that generates a random combination. my function looks like this: function random_gen($length) { $random= ""; srand((double)microtime()*1000000); $char_list = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"; $char_list .= "abcdefghijklmnopqrstuvwxyz"; $char_list .= "1234567890"; // Add the special characters to $char_li...

Why do the following snippets (one using "while" the other using "for") have different behaviors?

I have been trying out some basic exercises involving loops. Can someone tell me why the following snippets have different outputs? While Loop while (i<3) { while(j<3) { printf("(%d %d) ",i,j); j++; } i++; } Output (0 0) (0 1) (0 2) For Loop for(i=0;i<3;i++) { for(j=0;j<3;j++) ...

FPDF Header Question - Driving me crazy!

I am trying to generate a PDF that outputs Item Names onto a template PDF (using FPDI) with the Username listed on the top of each page. Every user can have a different number of items (i.e. if there are 1-4 items, only output one page; if there 5-8 items, output two pages, etc.) Here is an example of what I am trying to do: http://www...

When implementing an infinite loop, is there a difference in using while(1) vs for(;;) vs goto (in C)?

When implementing an infinite loop, is there a difference in using while(1) vs for(;;) vs goto? Thanks, Chenz ...

In Perl, is a while loop generally faster than a for loop?

I've done a small experiment as will be shown below and it looks like that a while loop is faster than a for loop in Perl. But since the experiment was rather crude, and the subject might be a lot more complicated than it seems, I'd like to hear what you have to say about this. Thanks as always for any comments/suggestions :) In the fo...

Why wont my while loop take new input (c++)

I've written a program to get a string input from a user and parse it into tokens and move a robot according to the input. My problem is trying to issue more than one command. The code looks like: void Navigator::manualDrive() { const int bufSize = 42; char uinput[bufSize]; char delim[] = " "; char *token; while(t...

Differences between a while loop and a for loop in PHP?

I'm reading an ebook on PHP right now, and the author noted that the difference between a while loop and a for loop is that the for loop will count how many times it runs. So take this: <?php for ($i = 1; $i < 10; $i = $i + 1) { print "Number $i\n"; } ?> But wouldn't this be the same as <?php $i = 1; wh...

While within a switch block

Hi, I've seen the following code, taken from the libb64 project. I'm trying to understand what is the purpose of the while loop within the switch block - switch (state_in->step) { while (1) { case step_a: do { if (codechar == code_in+length_in) { st...