Uploaded image for project: 'SystemDS'
  1. SystemDS
  2. SYSTEMDS-296

Add elif (else if) to PyDML

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Closed
    • Minor
    • Resolution: Fixed
    • None
    • None
    • Parser, PythonAPI
    • None

    Description

      "Else if" (elif) statements are useful since they avoid the need for nested if/else statements. Currently, DML has "else if" but PyDML does not have an equivalent "elif".

      As an example, here is DML containing "else if" statements:

      x = 6
      if (x == 1) {
      	print('A')
      } else if (x == 2) {
      	print('B')
      } else if (x == 3) {
      	print('C')
      } else if (x == 4) {
      	print('D')
      } else if (x == 5) {
      	print('E')
      } else {
      	print('F')
      }
      

      Here is the logical equivalent in PyDML using nested "if else" statements:

      x = 6
      if (x == 1):
          print('A')
      else:
          if (x == 2):
              print('B')
          else:
              if (x == 3):
                  print('C')
              else:
                  if (x == 4):
                      print('D')
                  else:
                      if (x == 5):
                          print('E')
                      else:
                          print('F')
      

      The nesting becomes especially challenging in a Python-like language as the number of nested "if else" statements increases due to the use of whitespace indentations to specify blocks of code.

      Attachments

        Activity

          People

            nishiyama Tatsuya Nishiyama
            deron Jon Deron Eriksson
            Votes:
            1 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: