Tagged Questions

A **loop** is a sequence of statements which is specified once but which may be carried out several times in succession.

learn more… | top users | synonyms

3
votes
3answers
158 views

Is there an idiom for a loop that executes some block of instructions between iterations? (In Ruby in particular)

I often need to do some operations in a loop and some other operations between the iterations. A simple example would be collecting words from an array into a string, spelled backwards and separated ...
-3
votes
0answers
92 views

I am developing a simple software application which should print a output from user input.How to do it? [closed]

How to get output like this in java using forloop to a text file? digraph G { main -> parse -> execute; main -> init; main -> cleanup; ...
3
votes
4answers
243 views

Declaring functions in order to avoid explicit nested loops

My programming professor has told me that it is a good programming practice (at least in C/C++) to declare a function with the inner loop when nesting loops (not for loops, since when, i.e. looping ...
-4
votes
1answer
94 views

Opposite of Collatz Conjecture [closed]

How can I write (in pseudocode) a program that halts only if the Collatz Conjecture is false ? Here is pseudocode for the case that it is true: function collatz(n) while n > 1 show n ...
2
votes
1answer
157 views

Loop Invariants in Python

I have a bit of experience with loop invariants but I'm not really clear on them. I'm trying to learn them through an example in Python. Can someone point one out or help me understand? I've ...
3
votes
1answer
125 views

Loop invariant vs Assertions

I have an exam on Programming Concepts this Saturday and I am struggling to find some information to understand some concepts better. What is the difference between loop invariant and assertion? To ...
7
votes
1answer
389 views

Loop fusion example using aspect-oriented framework

I had recently read a paper 'Aspect-Oriented Programming' by Gregor Kiczales and others, and found there the loop fusion example. Here is a definition of the loop fusion from the paper …the loop ...
-2
votes
1answer
259 views

Do-while Loop in Turbo C++ becomes infinite loop? [closed]

#include<stdio.h> #include<conio.h> #include<iostream.h> int calc(int x,int y,int t,int i) { for(int p=y;p<t;p+=i) { int z=x*p; cout<<x<<" * "<<p<<" = ...
4
votes
4answers
366 views

Decrementing/Incrementing loop variable inside for loop. Is this code smell?

I have to read lines from a text file in sequential order. The file is a custom text format that contains sections. If some sections are out of order, I would like to look for the starting of the next ...
3
votes
3answers
369 views

Is there a way to add unique items to an array without doing a ton of comparisons?

Please bare with me, I want this to be as language agnostic as possible becuase of the languages I am working with (One of which is a language called PowerOn). However, most languanges support for ...
4
votes
3answers
382 views

Does it make a difference if I declare variables inside or outside a loop in Java? [duplicate]

Possible Duplicate: Where do you declare variables? The top of a method or when you need them? Does it make a difference if I declare variables inside or outside a loop in Java? Is this ...
0
votes
3answers
2k views

2 Dimensional Arrays in C++

I started learning arrays in C++ and came over a little side note in the book talking about 2D arrays in breif. I tested it out and i was amazed that it could give the programmer the ability to store ...
9
votes
7answers
2k views

C# foreach improvements?

I run into this often during programming where I want to have a loop count index inside of a foreach and have to create an integer, use it, increment, etc. Wouldn't it be a good idea if there was a ...
-1
votes
4answers
616 views

How to improve my loop logic in programming?

I know how to do simple loops but I don't know what's going on when many loops are working together. For example: for (i=0; i <= 9; i++){ document.write(linebreak); for (m=0; m <= 9; ...
41
votes
5answers
8k views

Who created the idea(s) of the first loop constructs?

while (1) { if (1+1==2) { print "Yes, you paid attention in Preschool!"; } else { print "Wait... I thought 1+1=2"; } } As a developer, we all have to use ...