Forum > Beginners

A lot If-Else-If

<< < (6/6)

NightWing:
This code works, not as the syntax says it works but it works.

Thanks for the help

P.S.  I exceeded the character limit, that's why I post it in document
P.S2. I say bits no bytes

Handoko:
I tested the code, it compiles and runs. It seems you now already understand how to use nested if-then-else. So, if you want to improve your skill further you should re-read the posts from the beginning. All of their advices are true, the most notable problem is, you're doing a simple thing using a not simple solution. It makes the code harder to maintain and prone to bugs.

For your information, this is how to attach code to the forum:
Copy all the files into a new folder, except: the binary, *.exe, *.bak and the lib folder. Compress that folder and send the zip file to the forum.

And these are my recommend reading materials for beginners:

Lazarus tutorial for beginners:
http://wiki.lazarus.freepascal.org/Lazarus_Tutorial

List of tutorials with wide range of topics (graphics, database, printer, web, etc):
http://wiki.freepascal.org/Lazarus_Documentation#Lazarus.2FFPC_.28Free_Pascal.29
http://wiki.freepascal.org/Category:Tutorials

(Free) Pascal reference guide:
http://freepascal.org/docs-html/current/ref/ref.html

If you're looking for step-by-step Pascal tutorial, try these: http://www.pascal-programming.info/index.php
http://www.taoyue.com/tutorials/pascal/index.html

Some cool Pascal tricks:
http://lazplanet.blogspot.co.id/

Pascal video tutorials:
https://devstructor.com/index.php?page=tutorials

Lazarus IDE tricks (some are with animation):
http://wiki.freepascal.org/New_IDE_features_since

Ñuño_Martínez:
Ok, you fixed it, but I have an advise to make:

It is not a good idea to write so much code inside a CASE.  Instead you should create several PROCEDUREs or FUNCTIONs to do the work and call them from the CASE.  That will make things easier to read and you'll avoid this problem in the future.

Thaddy:
Well, correct, but the existing code can also be simplified by using ranges in the case statements.
Example:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---{$mode objfpc}{$J+}var   neptunoMP:qword = 1125899906842627;begin  // if (neptunoMP >= 1099511627776) and (neptunoMP < 1125899906842624) then  case neptunoMP of  1099511627776..1125899906842624:; // range  // etc  end;end.
If you do that everywhere the code becomes much more readable without all the ifs.
This is a feature of case blocks that many programmers forget about.

Navigation

[0] Message Index

[*] Previous page

Go to full version