Are multiple if statements within for loops considered bad code? | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 1

Are multiple if statements within for loops considered bad code?

I just started to write some code in Excel VBA and have never programmed before. Now that someone revisited my code, there were a lot of hints I got. Since I am starting to study computer science beginning next month I wanted some insight before implementing 'bad' habits. So while I was already very proud of the code I wrote I got told that using for loops inside if statements which are inside for loops and so on are bad because the program could crash because of spaghetti code. Is that true? Thanks a lot.

13th Sep 2017, 4:16 PM
Falkao
Falkao - avatar
8 Antworten
+ 6
Well, the program won't crash because of the spaghetti code... if there are no bugs, it will just run. If you're lucky enough it will run as expected. But everytime you have to search and correct a bug in dirty code after some time, you will just hate it. So, it's good to know how to write clean code. Take a look at this to start from - or simply google 'Uncle Bob' ;) https://cleancoders.com/
13th Sep 2017, 4:24 PM
Tashi N
Tashi N - avatar
+ 6
That depends on which language your university starts with. I guess it's easy for you to find that out on their website. And use the search function here. There are many threads about 'which language should I learn first'.
13th Sep 2017, 4:36 PM
Tashi N
Tashi N - avatar
+ 6
Maybe read something about oop in general, that will help you for sure. Java is a huge language, so the earlier the better...
13th Sep 2017, 4:42 PM
Tashi N
Tashi N - avatar
+ 6
Your welcome ^^
13th Sep 2017, 4:52 PM
Tashi N
Tashi N - avatar
+ 1
Thanks for the answer. Do you think it is a good idea begin with c++ as a basic language now and then start java when my studies start?
13th Sep 2017, 4:30 PM
Falkao
Falkao - avatar
+ 1
As I said I will learn Java in university. But since C++ is such a deep language and what a read online I think it can help me quite a bit
13th Sep 2017, 4:38 PM
Falkao
Falkao - avatar
+ 1
I will look into it. Thank you very much :)
13th Sep 2017, 4:50 PM
Falkao
Falkao - avatar
0
I would start with C++. It will be hard but the understanding that you can gain about what actually happens when you run code, is invaluable. Makes learning/understanding other languages easier.
17th Nov 2019, 10:05 PM
Joe
Joe - avatar