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

  • Thread starter Thread starter RadiationX
  • Start date Start date
  • Tags Tags
    Array Loop
Click For Summary

Discussion Overview

The discussion revolves around finding resources for problem-solving that involve FOR loops and arrays, with a focus on coding practices that are not language-specific, although Visual Basic is mentioned as a preferred language by one participant.

Discussion Character

  • Exploratory
  • Technical explanation

Main Points Raised

  • One participant inquires about websites that provide problem-solving exercises related to FOR loops and arrays.
  • Another participant asks for clarification on the programming language of interest.
  • A participant expresses a preference for resources that are not language-specific but mentions Visual Basic as a potential focus.
  • A detailed explanation of the FOR loop structure in C++ is provided, illustrating its components and functionality.
  • A participant shares the syntax and functionality of FOR loops in Visual Basic, including examples of how to initialize arrays and iterate through them.

Areas of Agreement / Disagreement

Participants have not reached a consensus on specific resources, and multiple views regarding the preferred programming language and approach to problem-solving remain evident.

Contextual Notes

The discussion does not resolve the question of specific resources for problem-solving, and there are varying levels of detail provided regarding programming languages and syntax.

Who May Find This Useful

Individuals interested in coding, particularly those looking to improve their skills with FOR loops and arrays across different programming languages, may find this discussion relevant.

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 language Specific, But If I Had To Choose A language 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
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K
Replies
8
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 21 ·
Replies
21
Views
4K
  • · Replies 17 ·
Replies
17
Views
4K