Enhance Your Coding Skills: FOR Loop and Array Problem Solving Resources

  • Thread starter Thread starter RadiationX
  • Start date Start date
  • Tags Tags
    Array Loop
AI Thread Summary
The discussion focuses on problem-solving using FOR loops and arrays, particularly in Visual Basic, while also referencing C++ for comparison. A FOR loop performs three main functions: it initializes a counter variable, increments it, and checks a condition to determine if the loop should continue. In C++, the syntax involves initializing a variable and specifying a condition, as demonstrated with a loop that executes code while a counter is less than a specified value. In Visual Basic, the syntax differs slightly, using the DIM statement to declare an array and a FOR loop to iterate through values. Examples illustrate how to populate an array with the seven times table and how to adjust the increment step in the loop. The content emphasizes the fundamental mechanics of FOR loops and their application in array manipulation across programming languages.
RadiationX
Messages
255
Reaction score
0
Does anyone know of a site that has some problem solving using FOR loops and or Arrays?
 
Computer science news on Phys.org
I'm Looking For Something That Is Not Langauge Specific, But If I Had To Choose A Langauge Visual Basic Would Be The One. Thx
 
A for statement does three things:

Assign a starting value to a counter variable
Increments the counter variable by a specified amount
Checks to see if the expression which makes the loop continue holds true

For example in C++:

for( int x = 0; x < 5 ; x++) { some code}

When the computer first enters the for loop the first thing it does is set x to the value 0. Then it checks the condition to see if it should enter the loop. Since x which is equal to 0 is in fact less than 5 it executes some code. When it finishes it increments x by 1 and then checks to see if the condition still holds. If it does it executes some code, increments x by 1 and checks to see if the condition still holds. This basic sequence happens over and over again until the condition is false, at which point it leaves the for loop.
 
In Visual Basic, the syntax is a bit different.

DIM A(10)

gives you eleven variables to play with, called A(0), A(1), ... A(10)

the FOR statement works like this:


FOR J = 1 TO 10

... do some stuff ...


NEXT


this makes J take the value 1 for the first pass through the loop, 2 for the second and so on up to 10 the last time through.

To make the values of A() be the seven times table, you could do something like:

DIM A(12)

FOR J = 1 to 12

A(J) = 7 * J

NEXT


If you want the loop variable to go in steps other than 1 you add a step clause:

FOR J = 0 to 20 STEP 2

PRINT J
' this loop will print 0, 2, 4, 6, ... 18, 20

NEXT
 
This week, I saw a documentary done by the French called Les sacrifiés de l'IA, which was presented by a Canadian show Enquête. If you understand French I recommend it. Very eye-opening. I found a similar documentary in English called The Human Cost of AI: Data workers in the Global South. There is also an interview with Milagros Miceli (appearing in both documentaries) on Youtube: I also found a powerpoint presentation by the economist Uma Rani (appearing in the French documentary), AI...
Thread 'Urgent: Physically repair - or bypass - power button on Asus laptop'
Asus Vivobook S14 flip. The power button is wrecked. Unable to turn it on AT ALL. We can get into how and why it got wrecked later, but suffice to say a kitchen knife was involved: These buttons do want to NOT come off, not like other lappies, where they can snap in and out. And they sure don't go back on. So, in the absence of a longer-term solution that might involve a replacement, is there any way I can activate the power button, like with a paperclip or wire or something? It looks...

Similar threads

Back
Top