Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Where does if-endif-statement end?

I have the following code:

for i in range(0,numClass):
    if breaks[i] == 0:
        classStart = 0
    else:
        classStart = dataList.index(breaks[i])
        classStart += 1
classEnd = dataList.index(breaks[i+1])

classList = dataList[classStart:classEnd+1]

classMean = sum(classList)/len(classList)
print classMean
preSDCM = 0.0
for j in range(0,len(classList)):
    sqDev2 = (classList[j] - classMean)**2
    preSDCM += sqDev2

SDCM += preSDCM
return (SDAM - SDCM)/SDAM

I would like to convert this code to VB.NET.

But I am not sure where the if-elseif-statement ends. Does it end after "classStart += 1"?

I feel it a bit difficult to see where the for-next-loops end as well in Python.

The code is taken from http://danieljlewis.org/files/2010/06/Jenks.pdf

Thank you.

like image 929
tmighty Avatar asked Oct 17 '13 14:10

tmighty


People also ask

How does Python know when an if statement ends?

In Python, the body of the if statement is indicated by the indentation. The body starts with an indentation and the first unindented line marks the end. Python interprets non-zero values as True . None and 0 are interpreted as False .

What is the end after IF statement?

An IF statement is executed based on the occurrence of a certain condition. IF statements must begin with the keyword IF and terminate with the keyword END.

Where do we use end if?

The endif command is used to terminate a multiple line if command. The command can either be specified as a single word, 'endif' or as two separate words, 'end if'.

How do you end an IF ELSE statement?

In the multiline syntax, the If statement must be the only statement on the first line. The ElseIf , Else , and End If statements can be preceded only by a line label. The If ... Then ... Else block must end with an End If statement.


1 Answers

Yes. Python uses indentation to mark blocks. Both the if and the for end there.

like image 117
Daniel Roseman Avatar answered Sep 21 '22 20:09

Daniel Roseman