C++ Tutorial: Day 5!
h
HahaYes (1052)

Day 5!

Bugs/Typos

Forgot semicolon. Thanks to @SpaceFire
Please upvote to help dominate the tutorial section.

REMEMBER. ALL FUNCTIONS MUST END WITH A SEMICOLON


Day 5!........... For Loops!

What in the world are For Loops?

Definition: For Loops are disigned to iterate a number of times.
Basically a template for a for loop looks like this...
for(initialization; condition; increase/decrease) statement; bla bla bla

So this would be a cool for loop for a SpaceX countdown.
Don't copy the code, try to write it yourself.

#include <iostream>
using namespace std;

int main()
{
	for (int n = 10; n>0; n--) {
		cout << n << ", ";

	}
	cout << "Liftoff!\n";

}

Initialization: Is executed, and sets it to some inital value.
Condition: This is checked, and if true, run, if false, end.
Statement: basically the statements enclosed in the curly brackets.
Increase: is executed and loops over again until false.


While Loops!

What are While Loops?

In a while loop, the condition is evauated first and if true, then the statement in sde the while loop will be executed. This will continue until the condition becomes false. When the condition is false, it comes out of the loop and goes to the next statement.
Syntax of a while loop:

while(conditon)
{
	statement(s);

}

A Example:

#include <iostream>
using namespace std;
int main()
{
	int i = 1;

	while(i <= 6){
		cout << "Value of variable i is: " << i << endl; i++;
	}
}

This will print out the numbers 1,2,3,4,5,6.

Ummmm that's it!

Challenges:
Build a launch sequence again,
but instead of it launching, make it abort.
Like this: 10,9,8,7,6,5,4,3, abort!
Using a while loop, make a infinite sequence.
Go study pointers, because the next one is going to be HARD

Hey everyone, all these competitors in the tutorials section must be wiped out.

Everyone upvote! (To dominate the tutorial section.)

Ummm featured shoutout.....
@TheForArkLD Always think the name is THeFORk

@Jakman A hardcore Rust programmer.

You are viewing a single comment. View All
Wuru (615)

Better than C++: [ link redacted by moderators for advertising ] Also a lot more in depth than this tutorial. :D

HahaYes (1052)

@Wuru considering every single competitior is trying to "shake up" my monopoly in the tutorial section, nice try.

Wuru (615)

Youll see with your dirty *ss C++ @HahaYes

Wuru (615)

Nobody wants short *ss tutorials with no good explanation @HahaYes

HahaYes (1052)

@Wuru sorry man, the monopoly is strong with me.

Jakman (378)

@Wuru lol his comrade is a Rust chad. It would be really bad for you if he helped him with his tutorials.

Jakman (378)

@Wuru any way @HahaYes is hustling with Cpp in a python world.

Wuru (615)

Yeah, personally I use Go more often than python and C++ but on repl.it i use python more. Though Java and Go are my most prominent languages. @Jakman

Wuru (615)

Personally Rust is fine, I just don't like the Syntax. @Jakman

Jakman (378)

@Wuru for you to call another ones projects and content ass is very disrespectful.

Wuru (615)

Look, we resolved it. Don't get all defensive for your friend without even looking into it. @Jakman

Jakman (378)

@Wuru cool. Just dont do that man. It aint cool.

Kognise (407)

@Wuru Hey, please try to be kind and respectful to fellow replers!

Kognise (407)

@Wuru Hey, please try to be kind and respectful to fellow replers! (again)

Wuru (615)

I know. We resolved it. It just got heated. We are good now :D @Kognise

Kognise (407)

@Wuru No problem, just going through the reports and doing my job as a mod :D

HahaYes (1052)

@Kognise we resolved it :) we are good now :)

firefish (308)

@Wuru You don't need to be so RUDE

HahaYes (1052)

@Jakman Thanks for the compliment

HahaYes is hustling with Cpp in a python world