الثابتة ‎Char.ranges()‎ في لغة Kotlin

من موسوعة حسوب
اذهب إلى التنقل اذهب إلى البحث

تعيد الدالة ‎ranges()‎ مجالا متدرّجًا (progression) تنازليًا من القيمة التي استُدعيت عبرها وحتى القيمة الممرّرة. ينبغي أن تكون القيمة الممررة أصغر من القيمة التي استُدعيت عبرها الدالة، وإلّا ستعيد الدالة مجالا متدرجا فارغًا.

البنية العامة

infix fun Int.downTo(to: Byte): IntProgression 
infix fun Long.downTo(to: Byte): LongProgression 
infix fun Byte.downTo(to: Byte): IntProgression 
infix fun Short.downTo(to: Byte): IntProgression 
infix fun Char.downTo(to: Char): CharProgression 
infix fun Int.downTo(to: Int): IntProgression 
infix fun Long.downTo(to: Int): LongProgression 
infix fun Byte.downTo(to: Int): IntProgression 
infix fun Short.downTo(to: Int): IntProgression
infix fun Int.downTo(to: Long): LongProgression 
infix fun Long.downTo(to: Long): LongProgression 
infix fun Byte.downTo(to: Long): LongProgression 
infix fun Short.downTo(to: Long): LongProgression 
infix fun Int.downTo(to: Short): IntProgression 
infix fun Long.downTo(to: Short): LongProgression 
infix fun Byte.downTo(to: Short): IntProgression 
infix fun Short.downTo(to: Short): IntProgression

القيمة المُعادة

مجال متدرّج (progression) تنازلي.

مثال

استخدام الدالة ranges()‎

في الشيفرة التالية نعرّف عددين x و y، ثم نعرّف مجال متدرّج p عبر استدعاء الدالةranges()‎ عبر x ونمرر إليها الوسيط y ، ثم نستخدم p في حلقة for:

fun main(args: Array<String>) {    
    val x = 9 
    val y = 4
    val p = x.downTo(y) 
    
    for (a in p) print(a) // 987654
}

أنظر أيضًا

  • الثابتةcategory‎ : تساوي القيمة القصوى لبديل وحدة اليونيكود (Unicode surrogate code unit).

مصادر