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

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
SpaceFire (101)

@HahaYes YEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

HahaYes (1036)

@SpaceFire SSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSSS

lightningrock (51)

YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA @HahaYes

sean098 (0)

AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY[email protected]HahaYes

HahaYes (1036)

@TheForArkLD FFFFFF Upvote All my projects

TheForArkLD (650)

@HahaYes Ok later ( ͡° ͜ʖ ͡°)

firefish (308)

@HahaYes NO SPAM PING ALLOWED OR I WILL HAHANO YOU AGAIN

HahaYes (1036)

@johnstev111 what do you mean. You literally just 404 ed us

theangryepicbanana (1635)

@HahaYes Please try not to mass-ping users

HahaYes (1036)

@theangryepicbanana I've stopped mass-pinging. Someone told me to stop before this. But thanks for the warning anyways. :)

dillonjoshua68 (65)

@HahaYes, could you challenge me to make a program, it’s been a few weeks, or months of learning python, and I understand a bit of OOP, classes and objects, exception handling (somewhat), scopes, functions, and beginner stuuff.

HahaYes (1036)

@dillonjoshua68 hmmm go make a calculator.

dillonjoshua68 (65)

What kind of Calc? Basic or with complex functions? @HahaYes

HahaYes (1036)

@dillonjoshua68 first do basic then complex. Sorry for the late reply.

dillonjoshua68 (65)

Np, and I already did the basic as previous school work, so imma improvise, and do complex, btw which functions should I add? @HahaYes

dillonjoshua68 (65)

I might have to use the math module for some, such as sin cos and tan, cuz those require unit circles to understand without a calculator @HahaYes

HahaYes (1036)

@dillonjoshua68 ummm look at that iphone calculator. Do like sqrt, cubic, log, sine, cos, tan that stuff