C++ Programming Tutorial 58 - Range Based For Loop

preview_player
Показать описание


~~~~~~~~~~~~~~~ CONNECT ~~~~~~~~~~~~~~~

~~~~~~~~~~~~~~ SUPPORT ME ~~~~~~~~~~~~~~

🅑 Bitcoin - 3HnF1SWTzo1dCU7RwFLhgk7SYiVfV37Pbq
🅔 Eth - 0x350139af84b60d075a3a0379716040b63f6D3853
Рекомендации по теме
Комментарии
Автор

you can use them to fill an array in this way:

for (int& n : data2)
cin >> n; // user input (or just n = value) you can even sum stuff etc.

but you can’t increment of a value x ex: cout << “Insert “ << x << “ value: “;
x++;

wekw
Автор

This one was hugely helpful. I tried putting it into a function with a vector instead of an array and it worked! You are the best!!!!

vegansynths
Автор

You can specify in the arguments of the function that you are passing a vector or array type like (std::vector<int> data) for use with the forange loop, in othe case you can also do (std::array<int, size> data) and you will also iterate with forange. I know the last example explanation is worthless because thats the point, not sending the size of an array by arguments, but I just want to show that it can be happen!. Thank Caleb! awesome videos I follow you everytime you upload a new video! Keep it going bro! I laught and enjoy every video!! thank you for all the patience and effort you put in to make those tutorials.. I'm from Paraguay by the way!! And I a cpp lover hahaha

triplefvr
Автор

Thank you so much. I'm just a few weeks into my self teaching and I was so utterly confused at the syntax and descriptions others have provided on this.
You fixed it for me. 👍

kyleeklund
Автор

5:35 Easy peasy, just pass by reference and you can use the ranged-base for loop even inside another scope

behzad.tabari
Автор

Very short and direct explanation, thank you!

danielcvlad
Автор

you're the life savior. Love you, man

Ben-pbct
Автор

great video for clarification. I was very confused about the style for rang for a loop.

codingwithelhacen
Автор

Thank youuuu! Explains it so much better than my lecturer hah

OutMagic
Автор

A good way to workaround the use of range-based for loops that takes arrays from functions arguments is to use std::vectors or std:: arrays instead sinse they are not pointers.

Byynx
Автор

I don't understand the explanation about decaying to a pointer?
In a previous video you said the STL arrays do pass as an object and not as a pointer. From this i would say the datatype of the data paramater in the test function is incorrect. It should be array<int, 60> and then it works..

jorisherry
Автор

You can get the array printing function to work by dereferencing the pointer by changing void test(int data[]) to
void test(int (&data)[size]) but yeah, you gotta specify how big should the dereferenced array be, which takes the whole advantage of ranged based loops, but who cares? who got it to work didn't we? :P

musicraftmenship
Автор

I think a workaround could be to pass the array as reference. this way it doesn't decay to a pointer afaik.

Astfresser
Автор

range based for loops look very easy. maybe that is why there are no direct exercises for it in ivor horton's beginning c++ 20 book.

magnus
Автор

Hi caleb how does the iteration happens in range based loop is it possible to print the iteration count.

mohamedazeem
Автор

Very short video and straight to the point with good explanation. Thank you bro!

robertjr
Автор

you come in brent rivera videos by any means caleb?

vandit_quantum
Автор

Well, you earned a subscriber today,
very easily taught, and simply explained such a hard topic.
Thank you for posting this video.
Peace.

killeraloo
Автор

Nice, but cannot see whats really happening in the loop

milgo
Автор

Wasn't there a way for me to put 2 numbers and get the value between? I need to use it for a couple conditions but I cannot find the name to search how to do it again T-T

xornedge
welcome to shbcf.ru